package com.esri.core.map;

import com.esri.core.internal.util.d;
import java.io.Serializable;
import java.io.StringWriter;
import java.util.Map;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public abstract class Domain implements Serializable {
    private static final long serialVersionUID = 1;
    protected String domainName = null;

    public String getDomainName() {
        return this.domainName;
    }

    public void setDomainName(String str) {
        this.domainName = str;
    }

    public static Domain fromJson(JsonParser jsonParser) throws Exception {
        Domain domain = null;
        if (d.c(jsonParser)) {
            String str = null;
            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                String currentName = jsonParser.getCurrentName();
                jsonParser.nextToken();
                if (currentName.equals("name")) {
                    str = jsonParser.getText();
                } else if (currentName.equals("type")) {
                    String text = jsonParser.getText();
                    if (text != null && "inherited".equals(text)) {
                        domain = new InheritedDomain();
                    }
                } else if (currentName.equals("codedValues")) {
                    domain = CodedValueDomain.fromJson(jsonParser);
                } else if (currentName.equals("range")) {
                    domain = RangeDomain.fromJson(jsonParser);
                } else {
                    jsonParser.skipChildren();
                }
            }
            if (domain != null) {
                domain.domainName = str;
            }
            return domain;
        }
        return null;
    }

    public static String toJson(Domain domain) throws Exception {
        StringWriter stringWriter = new StringWriter();
        JsonGenerator a = d.a(stringWriter);
        a.writeStartObject();
        a.writeStringField("name", domain.domainName);
        if (domain instanceof RangeDomain) {
            a.writeStringField("type", "range");
            a.writeFieldName("range");
            a.writeStartObject();
            RangeDomain rangeDomain = (RangeDomain) domain;
            a.writeNumberField("minValue", rangeDomain.getMinValue());
            a.writeNumberField("maxValue", rangeDomain.getMaxValue());
            a.writeEndObject();
        } else if (domain instanceof CodedValueDomain) {
            a.writeStringField("type", "codedValues");
            a.writeFieldName("codedValues");
            a.writeStartObject();
            for (Map.Entry<String, String> entry : ((CodedValueDomain) domain).getCodedValues().entrySet()) {
                a.writeStringField("code", entry.getKey());
                a.writeStringField("value", entry.getValue());
            }
            a.writeEndObject();
        }
        a.writeEndObject();
        a.close();
        return stringWriter.toString();
    }

    public String toString() {
        return "Domain [domainName=" + this.domainName + "]";
    }

    public int hashCode() {
        String str = this.domainName;
        return 31 + (str == null ? 0 : str.hashCode());
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj != null && getClass() == obj.getClass()) {
            Domain domain = (Domain) obj;
            String str = this.domainName;
            if (str == null) {
                if (domain.domainName != null) {
                    return false;
                }
            } else if (!str.equals(domain.domainName)) {
                return false;
            }
            return true;
        }
        return false;
    }
}
